<template>
  <div></div>
</template>

<script>
/*
  axios配置参数
**/
import axios from 'axios'
export default {
  name: 'axios4',
  created () {
    axios.create({
      baseURL: 'http://localhost:8080',//请求的域名，基本地址
      timeout: 1000,//请求超时时长(单位毫秒)
      url: '/data.json',//请求路径
      method: 'get',//请求方法(get post put patch delete)
      headers: {
        token: ''
      },//设置请求头
      params: {},//请求参数(拼接在url上)
      data: {}//请求参数放在请求体
    });

    //  1.axios全局配置
    axios.defaults.timeout = 1000;
    axios.defaults.baseURL = 'http://localhost:8080';
    //  2.axios实例配置
    let instance = axios.create();
    instance.defaults.timeout = 3000;
    //  3.axios请求配置
    instance.get('/data.json', {
      timeout: 5000
    }).then(res => {
      console.log(res);
    });

    //  实际开发
    //  有两种请求接口：
    //  http://localhost:8080
    //  http://localhost:9090
    let instance = axios.create({
      baseURL: 'http://localhost:8080',
      timeout: 1000
    });

    let instance1 = axios.create({
      baseURL: 'http://localhost:9090',
      timeout: 3000
    });

    //  baseUrl,timeout,url,method,params
    instance.get('/contactList',{
      params:{}
    }).then(res => {
      console.log(res)
    });
     //  baseUrl,timeout,url,method,params
    instance1.get('/orderList',{
      timeout: 5000
    }).then(res=>{
      console.log(res)
    });
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
